$(document).ready(function() {	
	var _pageId = parseInt($('#pageId').val());
	var navs = $('#main-nav').find('ul > li > a');
	
	$(navs[_pageId]).css('background-color', '#39c');
	
	navs.click(function(ev) {
		var pathName = window.location.pathname;
		var contentPath = pathName.substring(0,pathName.indexOf("/",1));
		var bgVal = $(this).css('background-color');
		if(bgVal == '#000' || bgVal == 'rgb(0, 0, 0)') {
			$('#main-nav').find('ul > li > a').css('background-color', '#000');
			$(this).css('background-color', '#39c');
			// return to the page.
			var pageId = $(this).attr('id');
			//Can not use this way, there are a security problem in IE9
			//$('#iframe_show_box').contents().get(0).location = "products/product_" + pageId + ".html";
			if(pageId != null && pageId != '') {
				if(pageId != "about") {
					var productType = $("#productType_" + pageId).val();
					$('#iframe_show_box').get(0).contentWindow.location = contentPath + "/baodacraft/product?pageId=" + pageId + "&productType=" + productType;
				} else {
					$('#iframe_show_box').get(0).contentWindow.location = contentPath + "/jsp/product/product_about.html";
				}
			}
		}
	});
	
	$('#header_nav li').hover(
        function () {
            //show its submenu
            $('ul', this).slideDown(200);
 
        },
        function () {
            //hide its submenu
            $('ul', this).slideUp(200);        
        }
    );
});

function getMoreProducts(productType) {
	var pathName = window.location.pathname;
	var contentPath = pathName.substring(0,pathName.indexOf("/",1));
	if(productType) {
		window.location = contentPath + "/baodacraft/pagedProduct?pageIndex=0&productType=" + productType;
	}
}

function getTitle(id) {
	if(id) {
		var title = $("#" + id).text();
		return title;
	}
}